Perhaps you got some file named: hey I am a long file name with spaces.jpg ;)
No it can't be that, see the "for" before hand, that will separate at whitespace by default (unless you tamper with IFS), so the variable tested will be without whitespace, I can only guess its a charset or similar that is causing the issue.
Anyway, good to see that it sorted it, point for the future, quote your variables in [ ] 's :)
z