Adjusting file write modes for compatibility with Python 2.7