The code runs to end and gets to exactly where I want it to be, but it never increments the number in the textfile.
Which makes it rather useless for your purposes, of course.
The first step is to pinpoint where it starts to go haywire.
I gave an example of what one might do in debugging, and so far it seems that the fopen() call fails.
Now you need to figure out why, otherwise you cant write anything to the file, and clearly you cant increment the counter if you cant write to the file.
For starters, double check that your permissions are correct.
Use [man]is_writable/man to explicitly test if the file can be written to.