Added .encode('utf-8') when writing out to a file.