A text file isn't something that supports zero-cost reorganization. It is simply a contiguous sequence of bytes. If you want to remove some bytes from the middle of the file (and by implication move all the following bytes up cover the removed bytes), you have to copy and re-write all those following bytes.
You have a few options. Read the entire file into memory, do your removal, and then write the file out. (hopefully to a temp file which you rename over on top of the original after successfully completing the write) Or do some fancy footwork with just reading in a buffers worth of data from the source file and doing some work on it.