That's the issue with txt files. You probably had too many people accessing it at the same time, and once the current count reading failed and returned false. Which would cause the counter to start from the beginning again. I'd suggest using a database for this, or, you could have a look at
flock(). And before writing to the file, make sure the reading didn't fail and you have a valid count which you increase and save to the new file.