Under normal circumstances Agents cannot distinguish individual bluepills from each other, so the bug is used to mark a specific bluepill and track his location.
The Machines' bug is analogous to the Zion operatives' red pill. Recall Morpheus' explanation of how the red pill works:
The pill you took is part of a trace program. It's designed to disrupt your input/output carrier signal so we can pinpoint your location.
transcript for The Matrix
The red pill is designed to help determine a specific bluepill's location in the real world, while a Machine bug is designed to help determine a specific bluepill's location in the Matrix (and possibly the real world as well). With billions of bluepills "just living out their lives" in the Matrix, it is impossible for Agents to find a specific bluepill among all the other bluepills in the Matrix, and it is impossible for Zion operatives to find a specific (ex-)bluepill among all the other bluepills in their Real World pods. To borrow a quote from Cypher:
But there's way too much information to decode the Matrix. You get used to it. I...I don't even see the code. All I see is blonde, brunette, red-head.
transcript for The Matrix
The red pill disrupts a bluepill's input/output carrier signal to "mark" him, and the bug similarly "marks" or "highlights" a bluepill to distinguish him from all the other bluepills. In a sea of indistinguishable blondes, brunettes, and red-heads the red pill or bug makes an individual distinguishable, as if that person was the only one with green hair.
Without the bug
Agents can "see" what any bluepill sees but since there are billions of bluepills it is impossible to look in real time at what all of them are seeing to pinpoint the location of Zion operatives anywhere in the Matrix. This exhaustive search can only be narrowed down if a bluepill sees something unusual (e.g. an operative breaking the rules of the Matrix) and/or if Agents know the rough location of the operatives (such as when they are in a chase, in which case they can check only what is seen by the relatively few bluepills in that area). In the case of the vagrant in the subway, the Agents had been chasing Neo and Trinity so they knew roughly where they were; they undoubtedly checked what the vagrant saw (especially since he was in view of a phone the operatives could use to jack out) and Agent Smith possessed him when he recognized Neo and Trinity.
With the bug
There are two known uses of the bug. In Neo's case the Agents were attempting to locate Morpheus, so they needed to know Neo's location when he met with Morpheus. Since the Agents can't distinguish Neo from all the other bluepills and Morpheus could meet Neo anywhere in the Matrix, they need to mark Neo with the bug. This also explains why Agents don't try to possess Neo after the bug is removed but before he actually takes the red pill -- once the bug is removed from Neo they can't tell which bluepill is Neo out of all the other bluepills in the Matrix. They don't know where he is, and so they cannot possess him.
The other bug appearance is in A Detective's Story. Agents placed an eye bug in the detective Ash in order to obtain Trinity's location when Ash met her on a train. The Agents had "hired" Ash to locate Trinity so they were obviously monitoring him. But they can't distinguish Ash from other bluepills under normal circumstances, so they put a bug in his eye to track the location of Ash specifically. When Trinity removes the eye bug the Agents can no longer track Ash, but they know the location of the bug was when it was removed and they know only a Zion operative like Trinity could remove it -- that's when Agents start possessing other bluepills on the train.
If Agents could simply possess any particular bluepill without a bug it would have been trivial for them to possess Neo as he met with Morpheus or Ash as he met with Trinity. For that matter, they could stop Zion operatives from unplugging any bluepill by possessing that bluepill just before he took the red pill. The bug allows the Agents to mark particular bluepills so they know where they are and which bluepill to possess.