in reply to Writing the contents of an array to a file

push(my @file2, $_);
Since you didn't post all of your code, I'm not 100% certain how you're doing your scoping, but I bet the my keyword there is why your @file2 is appearing empty or nearly so below. It will scope @file2 within that block (the if block, most likely).
my @file2; # scope it OUTSIDE of your block while (<FILE2>) { if (s/.../.../) { push(@file2, $_); } } # end your while here?? # ... print FILE3, @file2; # prints all elements