I know this is late but I wanted to tell you that my son had the same problem with 2s and 5s and it wasn't a matter of not knowing how to write them. It just happened sometimes and it happened more often when he was younger. My son described it as a glitch. It was so annoying that it was one of the reasons he hated math even though he was good at it. The only way we could get through math was if I acted as his scribe after he did only a few problems. I wish that I hadn't tried to force him to do more. The reason I tried to force him to write more problems and show his work was because I was afraid something might happen to me and he would have to go back to a bad public school that would not allow any accommodations. I thought if I just pushed him enough he would be able to do more, that he would somehow build up strength and endurance just by doing more, but his hands always hurt after five minutes and I got really stressed about it because I could see it wasn't a simple matter of having him practice writing numbers. It was a physical issue that he had no control over. He could feel my stress and he already felt bad enough about the difficulties. I know I am the reason he hates math.
Fast forward to 9th grade algebra and factoring quadratics. I do well to get him to write out one problem. He will tell me exactly what to write, after he tells me how much he hates math and tries to talk me into letting him do science or economics or anything else, but he can easily do the math if the writing issue is accommodated. When I have him write out a problem he will only do it on a whiteboard so that he can quickly erase only what he needs to and reuse some of he has written to cut down on the amount of writing. I am hoping that he will eventually be able to CLEP out of college algebra and be done with math. I also hope they will let him use a whiteboard so that he can do math that he knows how to do but has trouble doing because of a physical disability that affects the amount of writing he can do.