Convert to python 3, write to output file instead of standard output