in reply to Perl prints junk before file

There's a number of hidden factors here that make direct answers to your question mostly meaningless. Without more information, there's not a whole lot to go on.

Possible solutions:

-- 
Education is not the filling of a pail, but the lighting of a fire.
 -- W. B. Yeats