in reply to write to .jpg error problem

This can help you find out where you are (cwd) and what file you are trying to open and whether destination's folder is valid like others have suggested:

use Cwd; print "Now at dir: '".cwd()."' and arg is '$arg'.\n";