Bugs fixed in writePGM and writePGM func.