in reply to Random Image Generator

Additionally to all the above suggestions, you should check that directory that you expect script to run in is actually the one you exptected:

$dir = "."; opendir(DIR,$dir) || die "Unable to open $urldir: $!";