in reply to Re: System(), writing to a new file
in thread System(), writing to a new file

Oops!
I saw there was no redirection in the OP's code. That's why I suggested redirection in my post.
But I missed the sort filename > newfilename comment in the OP text.