in reply to Problems writing to an external file

When an open() fails, Perl puts an error message into the special variable $! (see perlvar for details).

Try   open(TEST, ">$filename") or ErrorMessage("$filename: $!"); The contents of the error message will distinguish the type of failure.