open(FH, "> filename.txt") || die "Cant open file: $!\n"; select(FH); #rest of script here to print output to filename.txt close(FH); print "Nothing prints here after the close(FH)";