Hi,
You're not actually specifying what is going wrong, but there is definitely an error in your script: You open the file for read and write, you read the file, and then you're trying to remove the file again -- however, without closing the file first. That will cause a access violation error.
You should close the file first, and then remove it.
Second, there is no need for the 2 shell calls - just write the next value into the file using PHP and then fclose it.
HTH
Edsko