Hello : )
It's called a "short term energy release behaviour"... it relieves stress and anxiety for the short term.
It's also called "self mutilation" and that's not a happy subject. When you break your skin whether accidentally or on purpose, the brain releases endorphins. These endorphins make you feel a little better for a little while--but it's not a permanent fix, that's why you've got to do it over and over.
I do it too... I'm sure all of us that do this kind of thing have our own "special ways" that we do it too!
I'm learning to overcome it by first becoming aware when I'm doing it--sometimes I don't even realize it until my fingernails are already bloody! Other times I do it intentionally and not by force of habit.
So, awareness... and choosing NOT to do it, and find another way to get those endorphins released.
Take an ice cube and hold it on a sensitive part of your skin--keep it there until it melts. It will hurt without damaging your skin and you'll get the endorphins. There is also going for a brisk walk, jump rope, clap your hands, dance, swing your arms round and round, BREATHE... there are lots of things one can do to release anxiety and gain the brain fix! I understand~I have scars and "active sites" now--but I'm doing MUCH better. Let us know how you're doing! I wish you well. : )