What happens if you just write one achievement per key press instead of attempting to write all of them in one function? I have a feeling that the issue could lie in attempting to unlock multiple achievements at once.
Try splitting this up into a few different key presses and see if you still experience the same error.