Are you using a screen protector? If so, remove the screen protector and re-test.
If the issue is not due to a screen protector, random or unexpected input from your Apple Pencil will be due to a screen hardware issue. The Pencil itself will either work, or it won't.
A screen hardware fault will require assessment and repair.
A broken or faulty Apple Pencil can only be replaced. Other than the user-replaceable Pencil Tip, the Pencil has no serviceable components.
If you cannot resolve the problem, you would be best advised to visit the Genius Bar at your local Apple Store or Apple Authorised Service Provider (AASP) - where the technicians will be able to test and assess your iPad and Pencil:
Genius Bar Reservation and Apple Support Options - Apple