You could switch to giving files randomly-generated names. It's not as helpful when debugging but way less of a hassle to code and less risk of issues like this one. I've been using UUIDs lately.
WeBWorK Main Forum
Problem with image files/graphs
This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 10 posting(s) in 1 day