in reply to use of uninitialised value

If the warning is from the open() line, either $upload_dir or $filename is undefined.

If you want more info on warnings and errors, try doing

use diagnostics;
at the top of your program, or look them up at the perldiag manual page.