If you've considered all the above good advice and you
still want to store record number in the text file, you
could save yourself some line-counting time by keeping the
last-used number in a configuration file (or *gasp* the
Registry if you're suffering from Windows).
You still have the problem of stopping other processes from
messing you up though!