Looks like you are on to something...

about 348k memory with empty image folder

about 188k memory with image (one or more) in folder

down to 82k after script crash

mem with script running normally (no image in folder at startup) and has stored at least one image in folder
So, if I understand, if there is an image in the folder at startup then there is not enough mem to run the script. However, if the script gets to start with an empty folder, it stores images without running out of memory. Until next time you use the camera! Pretty clever! Gotta luv computers! Ha, ha.
Whaddya think?
Terry