Hey Tinaw, sorry I didn't spot your message sooner.

What it's probably doing is saving the screengrabs as either PDF files or PNG files. Since the computer is expecting a file called "grab0005.jpg" to be a jpeg, it sees the data isn't in the right format and craps out. Try it again, but with:

do shell script "screencapture ~/Desktop/grabs/screenshot" & a & ".png"

Instead of ... & ".jpg", and see if the files open. If that doesn't work, try ... & ".pdf". It might be trying to save them into any of those formats.