It depends on your pet. There are quite a few useful things that pets can do. Here are some of the basic benefits.
BUC Test
All pets are reluctant to walk on cursed items. They will rarely walk on them, and if they ever do walk onto a tile with a cursed item, it will say that the pet moves reluctantly. This is a great way for non-priest characters to assess whether an item is safe to equip or not.
Stealing
Pets like to pick stuff up off of the floor, and this can help you steal from shops without getting caught. You can read up some more of the basics here, which also links to an in-depth spoiler.
Riding
If you have a saddle, then you can choose to mount certain pets such as warhorses, dragons, and kirin. This lets you move at their speed, improves your carrying capacity, and may also convey other benefits such as flight in the case of flying mounts. Unfortunately, saddles are exceptionally rare and the only guaranteed one is given to Knights at the start.
Storage Capacity
Pets can also be a great way to get people offload stuff, if they're certain types. There are some ascension strategies that use giant pets to carry loads and loads of gems on the way to the end-game.
Warning
It's a bit dangerous and not very nice to the pet, but if it does wander off, it can alert you to particularly dangerous foes. Or, if it's powerful enough, it can dispose of them before you even learn of the threat.
Doing Destruction To All Who Oppose You
Probably the real big benefit of pets is to help you kill things dead. Pets don't level in quite the same way you do - instead, they get stronger much quicker based on how many creatures they kill. Pets such as your starting cat/dog will eventually grow into large cats and large dogs, while pets such as dragons will just grow to higher HP and will be hardier. In some ways, you can easily let pets become more powerful than you, which lets them face the more powerful enemies without risking your own health. Often times, you can have pets that are much faster than you, deal more damage than you, or otherwise possess supernatural abilities that you do not, which makes them exceptionally powerful at the right times.
You can help get better pets by using a Polymorph trap. If your pet doesn't hit get killed in the process, it's possible to get crazy things like mind flayers, giants, or dragons. Gray Dragons are pretty common, just because they actually are something of an end point for polymorph.
Using pets to fight is also the key strategy for any pacifist run, as it's basically the only way to get past tough opponents on account of the whole you not hitting enemies.
There are also some very specific benefits for having certain pets. For example, a pet Yellow Dragon can eat cockatrices safely and is immune to their petrification. And of course, a cockatrice pet can turn all of your opponents to stone, though that has its own downsides.
In all cases, what really helps with pets is to find a magic whistle. This item is a re-usable tool that will immediately summon all of your pets straight to your side. These can be usually found very early, often on the ground in the Mines or in tool shops.
You may also consider reviewing the advice from this question, both answers include a good amount of strategy for keeping your pet healthy, happy, and ready to serve you.