better support for python 3 with unicode file writing