One method would be to read the whole text file into memory, modify/replace the line(s) you want to insert into, and then write the strings back out to text file, overwriting the source file.
A somewhat safer method would be to instead write to a second file, then when done saving the output, delete the source file and rename the output file to the source file's name. This would prevent corrupting data if for some reason the write process throws an exception.