The best way by far would be to empty out this text file whenever you copy files to the db. That way, the txt file will only contain records that must be added whenever you parse it. If you can't delete or empty the text file, you might be able to keep track of the 'last line processed' and only start with the next line when you have to process the file again.
For example, on day N I run my script. It goes to the DB or to some other text file where I have stored my 'last line processed' value. When my script retrieves this value, I can see that $last_line_processed is 38000. I know then that I need to process the text file again, but only starting with line 38001. So I would open the text file, reading each line and I would simply discard the first 38000 lines without even looking at them. I would start with line 38001 and could be sure that it didn't yet exist in the DB so I would simply add it without bothering to check the DB.
This of course doesn't work if, for some reason, you would not want to add these new lines in the text file based on some other db-related reason.