When I used to pray I had a hard time pronouncing the words in my head, so in order to help me during Tashahud, I would rock back and forth because it made it easier to get the words out. I am trying to stop that now, but do you know if this invalidates the prayer?
Excessive movement, which is not part of Salah will nullify Salah except for making necessary movements when needed such as: wiping the nose, scratching, etc.
But for the Rocking back and forth during Tashahud which is inadvertently and not for changing the shape of Salah, it is better not to do. Actually it does not invalidate Salah but would reduce Oblation of Salah.
In principle, words of Salah should be said while the body is resident. So, expression of tashahud should be while the body gets resident after sujdah (prostration).
- Tauzeeh-Ul-Masails, part of Salah