in reply to Question on file I/O

Yep, for future reference you'll want to make sure that you open your file with:
open(OUTFILE2, '> $filename') or die "Couldn't open '$filename': $!; stopped"
which would have told you what was going on at once.