It has nothing to do with local storage. right(text,1) expression takes the last character from the text. So if your text is "mykey7", it will extract the character "7". Then the int() expression turns it into a number 7.
If your text is "mykey17", it will still only extract the last character!
So if you want to have double digits in key names, you need to use right(text,2). But you also need to add an extra zero in front when the number is less than 10, use zeropad() expression for this.
Local storage set key "mykey" & zeropad(imagenumber,2)
this will generate a key like "mykey03" or "mykey18"