How can I use pgn-extract to remove a game from a pgn file when there is an illegal move? How can I use pgn-extract to remove a game from a pgn file when there is an illegal move?
pgn-extract will do exactly that if you give it an input file and say where you want the correct games to go. For instance:

pgn-extract --output clean.pgn games.pgn


will put only the valid games from games.pgn into clean.pgn, reporting any errors on standard output. If you want to have a record of the errors then you can use the -l flag to specify a log file; e.g.:

pgn-extract --output clean.pgn -lissues.txt games.pgn


There are lots of additional options/flags described in the documentation.

Disclosure: I am the author of pgn-extract.