Anyone for a little perl?

I'm writing a perl program that outputs three separate files. The basic format is:

open(FILE1,">file1");
print FILE1 text;
...
close(FILE1);

open(FILE2,">file2");
print FILE2 text;
...
close(FILE2);

open(FILE3,">file3");
print FILE3 text;
...
close(FILE3);

However, after the program completes, and you go to look at them in vi, file1 and file3 both contain an [incomplete last line] message, but file2 does not.

The problem is that the output files are actually executable programs, and the only way to run them is to delete the last line and retype it in.

Does anyone know how to avoid this result?

Read 'text' files one-line-at-a-time and print/write them one-line-at-time until the read reaches a EOF (end of file) symbol.