PPM has an interleaved format with RGB decimal, but runs top to bottom. It’s actually an ASCII format.
The simplest approach is probably just to read GL_RGB packed unsigned bytes and loop through with a byte pointer writing out the rgb in byte order with newlines are appropriate places. You’ll have to start at the last OpenGL line and work forward since OpenGL will read bottom to top first, but both are left to right at least.