in reply to Writing to a file: problem

The line:
print (OUTFILE);

prints $_ to the filehandle. But what is $_? It's set by the while loop, so it has the value of the last time the while was checked. Which was at the end of the file, and hence $_ is undefined.

That's why you get your warning, and that's why the file is empty - undef stringified gives you the empty string.

Abigail