Purge temp files automatically?

Im doing some photo manipulation with mini-magick.

Sometimes, in one action, it will work on 15+ photos and create like 40+
temp files. It seems that the temp files will get deleted while the
action is happening.

This causes about 1 out of 10 photos to trigger an error since the temp
file containing the photo information gets deleted before it finishes
working with it.

Has anyone seen this happen before?

Aryk