use strict;
use warnings;
$| = 1;
my $filename = 'foo.txt';
open (FH, '>', $filename) or die "cannot open $filename for writing: $!";
my $wasout = select FH;
print "In the file!\n"; # Here you print on FH which is open for writing. No problem.
close FH;
print "OMG, a warning!\n"; # Here you print on FH but it is closed so a warning is shown
select $wasout;
print "Sweetness and light.\n"; # Here you print on STDOUT again - no warning. Joy!
exit;
####
print() on closed filehandle FH at sel.pl line 11.
Sweetness and light.
####
In the file!