I assume you're OK with reading a file.
Now you need to "flip a switch", which tells you when to write, and when not.
01 FILLER.
05 FILLER PIC X.
88 LAST-RECORD-WRITTEN VALUE "Y".
88 LAST-RECORD-NOT-WRITTEN
VALUE "N".
After you successfully OPEN the output file:
SET LAST-RECORD-NOT-WRITTEN TO TRUE
In your loop to read to end-of-file:
IF LAST-RECORD-WRITTEN
SET LAST-RECORD-NOT-WRITTEN
TO TRUE
ELSE
PERFORM WRITE-OUT-THE-INPUT
SET LAST-RECORD-WRITTEN TO TRUE
END-IF