Corrected a bug in utf8 output - basically changed print to sys.stdout.buffer.write