in reply to using die in CGI context / 500 errors

Die will cause your browser to fail on execution of the script. Add:
use CGI::Carp(fatalsToBrowser);
It's likely your web browser doesn't have permission to read the file and is dying because of that. Also try
open(LOCAL, ">$dir/$name") or print $!;
Good luck.

    --jb