Depends on your transit destination. If its UA981 and you leave the gate, your bag will be scanned/searched once you try to come back to the gate. Likewise for some other carriers/destinations (such as BA, Lufthansa, etc). Obviously if you remain in the gate, there will be no opportunity for your bag to be scanned/searched unless there is an extraordinary circumstance. But the OP did mention he intended to go to the lounge.