in reply to $twig->flush causing output to stdout?
It seems to work fine except when sent a 2nd filename, the output suddenly goes to STDOUT instead of the $infile.
2nd filename?
Where in the code you posted is this second filename?