Add flushing after writing to make Python 3 work