Hi there: this screw from my bathroom vanity handle has broken. I'm curious about the two grooves that you might be able to see on the remaining screw. Do they serve any purpose? Should I be trying to find a replacement that offers those two grooves? Or are they not necessary?
Those are called breakaway machine screws or just breakaway screws.
They come in handy when installing cabinet hardware (handles/knobs etc.) in materials that differ in thickness or you don't know the thickness. As you have seen, they are also used in many other applications such as bathroom hardware.
The slits in the thread make it easier to adjust the size of the screw to the application without messing up the threads.
Hold the head of the screw in pliers/vise etc. And use another pair of pliers just past the slit on the threads you don't need... Bend the slit up and down and snap.... The piece you don't need breaks off and the thread is still good on the part you need.
You could also just use lineman pliers to cut the screw at the slit of the length you need.
Do you need them? No, you could just match the length and thread type and get that screw. But if you have to cut non breakaway screws, you can mess the thread up and it wont grab the object you are securing. I would personally get the breakaway screws.
The screw with grooves is a breakaway screw, made so that it can be easily cut or snapped to the correct length. Perhaps the broken one was over-tightened, causing the breakable portion to snap. They probably came as part of the installation kit (so that it could fit many different doors) and aren't strictly required.
In either case I would just take the broken screw(s) in to a hardware store and pick out a replacement. One with thread on the entire length is probably slightly stronger and cheaper, if available in an appropriate length. I recommend replacing both of the screws at the same time, and any associated nuts/washers - it'll save you a second trip and make sure that everything is the same size.