maybe .. it might also be good to see newtext-x.lsp as well
One thing I noticed is that you are relying on global variables from one function to be used in another function, for example, ordernum is set in write2file, at first you set it to an arbitrary value 'ff, presumably set in your vla-GetCustomByIndex function. If that fails, and ff is set to nil then you have some serious problems.
Since you don't know exactly where the function fails, and since it fails only if it loads newtext-x.lsp then I would have to conclude that is where the problem lies.
Perhaps your reliance on global variables has bitten you in the proverbial ass ... then again maybe not.