open(FH, "output.txt"); my $oldfh = select(FH); sub_that_writes_to_file(); select $oldfh; # reset to whatever it was close FH;