chdir "/home/main/sub/newfiles"; open (WRITE,">$file") or die "could not open $file $!"; # write stuff chdir "/home/main/cgi-bin";