Is it possible that the sub opendb() isn't checking for success, and thus, upon failure, is returning an undef 'Handle'?
If that's the case, it's also possible that as the script is cleaning up and going home (and doing its garbage collection), it's trying to close that undef filehandle.
Dave
Comment on Re: Uninitialised value during global destruction