use strict; chdir "c:/Users/Admin"; my $fname = "output.txt"; #open OUTPUT, ">$fname" or die "$fname: $!\n"; is more common but you will miss the message when run by scheduler unless(open(OUTPUT,">$fname")) { exit } print OUTPUT "This worked\n"; close OUTPUT;