This output doesn't correspond to the code what you have posted above. Show us the same code that you are running.
This error seems to be due to permissions or ownership of file /tmp/output.1224. Do
ls -l /tmp/output.1224
Check the ownership and permission on that file. You may not have write permission on it. If so you can change your output log filename to something that is more specific than output.$$ as many other processes may have used the same name. Something like
err_file=/tmp/MyProgramName_output_$$.err
mail_log=/tmp/MyProgramName_output_$$.log