hmmm, are you SURE you're running the script from the command line? do you run cmd and then execute the cript? because if you are, the window shouldn't really ever close.
but anyway, redirecting STDERR is probably your best bet:
open(LOG, "+>log.txt");
*STDERR = *LOG;
*STDOUT = *LOF; # just in case some errors go to STDOUT
...