Fix bug in write_pnm for Python 3