Pencils are dangerous in space—they can cause fires. Also, the “space pens” were not developed with taxpayer money but instead by a private company, and they actually saved NASA a lot as they bought them for dollars instead of hundreds or thousands as they did with pencils.
Edit: didn’t see the other reply, but it’s pretty much the same idea