in reply to output file

I'm not sure if I completely understand your question, but it seems to me that you can open a new file and store the text in that file:
open(TEXT, ">textfile") or die "$!"; . . . print TEXT $some_text_line; . . . close(TEXT);
If you really want to have temporary files, take a look at POSIX::tmpnam], IO::File::new_tmpfile or File::Temp.

Arjen