Small fixes to writePieceToFile()