Settings → Bluetooth & Devices → Pen & Windows Ink
Make sure:
“Use pen as mouse” is ON
“Ignore touch input when using pen” OFF (temporarily for testing)
Try to write on Microsoft Whiteboard, Paint, OneNote.
If it doesn’t write in any app, it's likely hardware-related. And replacing the pen will be the right decision.
Best option is replacing the pen.