You could save yourself a lot of trouble if you store a field in the very top line that indicates the last date of a successful write - so you know exactly where to look each time.
When you append, append to temp file and update the last write date. Then mv your temp file to be the new version of the file you're updating.
Comment on Re: check to see if a file has todays data in it, if it has exit if not then add data