No Windows person. So in complete darkness. I could imagine that the problem is in Windows ACL. The IIS process can create files in moodledata/cache but can not delete them!
May be you can circumvent the problem with the script. But if it happens in other places like moodledata/filedir, the upload directory of Moodle, you are in for trouble. The directory will only grow, never shrink - if you are lucky. If not so lucky, it will create misunderstandings between the meta data recorded in the database and the actual files in moodledata/filedir/. To clean such a mess you need much more that a shell script.