You cannot insert data into files because file I/O does not support that. So you have to rewrite the file. Read it in line by line, write each line to the new file, and if the condition is TRUE then write the new line, then continue with the next line from the original file. Then you can delete the old file and rename the new file to the old name, thus giving the impression that data has been inserted.