When I try my code on Check50, it says it doesn't recover the last file correctly, because it's "Checking for file 015.jpg.". The last file is 050.jpg, and it even says so in cdn.cs50.net/2016/x/psets/4/pset4/pset4.html
But you should find ultimately that the image contains 50 JPEGS
So it shouldn't be looking for 16 JPEGS, but instead 50. Is that a mistake in how the checking is written (as in, it says it checks 16 but actually checks 50) or is something else wrong there?