I somehow managed to ride over a screw that pierced through my tire and was long enough to reach the rim. It scratched the rim a few times (for as many wheel revolutions that it took me to stop the bike); see picture below. When I put my finger over the scratches they feel quite rough which will certainly not be good for the tube I imagine. Is there any way such damage can be fixed without having to replace the rim?
In the photo it looks like you have damaged the rim tape, not the actual rim. You should be able to replace it without touching the rest. The tape on photo says tubeless ready: if you are planning to go tubeless you should replace it with similar one, but if you plan to use tubes, any high pressure tape will work.
I would peel the rim tape off, and then carefully file off the high spots.
Then stop and reassess and if it seems okay I'd use emery cloth to smooth it out completely. If the pits feel too deep, you might fill them with JB Weld or similar. You need a smooth surface for the tube to rest on.
If you reuse the rim tape, consider flipping it 180 degrees to get the damaged rim against another area of fresh rim-tape. Or cover the damaged bits with a sticker/tape, or ideally replace the rim-tape completely, its a lot cheaper than a rim.
I've used an aluminium rim where a screw came completely through the rim, poking out between two spoke nipples. After changing rim tape it worked well for years. I still ride it on my 26" MTB. But you make a judgement call once the spiky bits are cleaned up.