not sure exactly how to do it, but you could have the script, before it stores the file, get a list of all the files in the directory, use a reg exp to cut off all but the end of the newest file name, increment the number by 1 and stick the filename back together, then proceed to store the file.
For Example:
if you wanted them to be named
image001.jpg
image002.jpg
image003.jpg
and so on, have the script strip off the image and the .jpg from the filename, increment the number by 1 and then stick the filename back together.
so if image0010.jpg was the newest file in the directory, take image0010.jpg, take off the image and the .jpg so you're left with only 0010 then increment 0010 by 1 so you get 0011, then stick it back together as image0011.jpg, give image0011.jpg as the filename, and proceed to store the file.
I'll sit down later and see if I can bring this theory to life, but no promises. I'm still trying to figure out this regular expression stuff.