Blender 2.8 (Python) - what does this console error mean
That error is coming from your OpenAL (Open Audio Library) which encounters a problem. It may be unrelated to your issue though. You can temporarily disable the sound system by starting Blender from the terminal with the -noaudio flag or set Audio Device to Null in the preferences (Edit > Preferences). 

If your script still fails to write to disk it's likely a bug in your script and not caused by a problem with OpenAL. You can revert the changes in the preferences if that's the case. Should the problem disappear with the suggested settings, then it would be nice if could write a bug report (Help > Report a Bug in Blender).