Our Jungle Carpet Python was doing this recently for probably two reasons, 1) trying to escape and 2) stress about enclosure size. We moved him up to triple the size enclosure and he is no longer doing it.

Worth giving it a try.

If he gets really raw, use triple anti-biotic ointment, but NOT Neosporin brand (has an anesthetic that is bad for them) - sparingly. Of course, as usual, as your vet first!

Good luck.