Few changes to support running on python3
Encode to utf-8 at the FileWriter level so that we catch all undecodable strings