You already have the image that's being displayed for this invocation, so you have many options:
- Update a key in a tied hash with the file name as a key
- Append it to a logfile and let another script parse it
- Use a full-blown database
- Open a file named the same as the image, read a number from it, add one, and rewrite the file
I've listed those in my preferred order. There are many good options.