There is no mechanism to change text files "in place" -- not unless the replacement is exactly the same size as the original.
You need to read the file and write each line in turn to a new file, except writing the new versions of the lines instead of writing the old versions. Then once past the part to change, keep reading from the old and copying to the new. Close the files. If needed, rename the new file to have the name of the old file.