I had similar mystic files caching when using fgets and feof - both did not notice that underlying file was changed.
Turns out php has files/directory caching that needs to be cleared if you expect the files to get changed during php script execution:
clearstatcache();