If there is a solution to writer's cramp out there I'd love to hear it.
Keyboard?
Unless you're handwriting for the fun of it (and is it really that fun, if it causes pain?), once you leave school it seems to be entirely possible to get through life without writing anything more lengthy than the occasional sticky label or back-of-the-envelope calculation.
(Disclaimer: I'm biased, not being a natural handwriter. I can do it neatly and without pain, but it's excruciatingly slow. This caused no end of problems at school. Being able to write without drawing each letter by hand was a revelation, and other than when doing maths, I never looked back.)
Otherwise, perhaps the pencil is too narrow. Try something thicker, or one of those grip thingies?