What is PGM?
Greyscale, uncompressed, with a header you can read in a text editor. PGM is part of the netpbm family, and it exists because sometimes you want pixel values you can do arithmetic on without a decoder in the way. Image processing and computer vision code loves it.
What is BMP?
The Windows bitmap, which stores pixels raw with no compression worth mentioning. Files are enormous. It survives because it's trivial to read - if you're writing an image loader from scratch or feeding an embedded display, BMP is the format that needs no library.