Please note that there is a bug report open for the currently broken safe_mode behaviour on this function:
http://bugs.php.net/?id=35060
According to the PHP staffer who has responded the docs are wrong (I don't agree but I'm also not their employee).
The work around is to use touch() (or any other file system function that can do this) to create the file first before using imagejpeg().