Implemented the write ply function into the code