Why did the US use the AIM-9X Sidewinder missile to shoot down the Chinese balloon when the same job could have been done with a gun at a much lower cost?
The AIM-9X Sidewinder missile is a triple-threat missile that can be used for air-to-air engagements, surface-attack and surface-launch missions without modifications.
The weapon is configured for easy installation on a wide range of modern aircraft, including the F-15C Eagle, F-15E Strike Eagle, F-16 Fighting Falcon, F/A-18 Super Hornet, E/A-18G Growler, F-22 Raptor and all F-35 Joint Strike Fighter variants. As part of National Advanced Surface-to-Air Missile System, best known as NASAMS, AIM-9X adds a short-range layer of defense.
The AIM-9X is the weapons that has been used to shoot down all the unidentified flying objects that violated the North American airspace in the last days, from the Chinese spy balloon shot down off the coast of South Carolina to the octagon shaped object shot down over Lake Huron.

Why did the US use the AIM-9X missile to shoot down the Chinese balloon (and the other flying objects) when the same job could have been done with a gun at a much lower cost?
Abhirup Sengupta, an aviation expert, explains on Quora;
‘In 1998 Canadian CF-18s tried to shoot down a rogue weather balloon that went out of control drifting between 27,000 to 37,000 ft. It took 6 days for the balloon to fall despite RCAF CF-18s firing over 1,000 rounds of ammunition in multiple attack-runs. While the attack caused extensive punctures on the balloon, it failed to fully release the helium gas which kept the balloon flying. In fact, instead of falling on the ground the balloon ended up drifting across Canada and out to the Atlantic Ocean for almost a week.
‘These high-altitude balloons are quite large and use Helium gas which isn’t flammable. Creating a couple of holes won’t ‘pop’ them as one would imagine, it would only result in them leaking Helium very slowly. Since you can’t control or anticipate where they might drift after multiple punctures you might just end up deteriorating the situation as was the case with Canadian balloon.

‘Their unexpected behavior combined with the massive size also creates a risk of collision or attacking Fighter aircraft getting in proximity to debris field. This risk only increases when you’ve to operate above 60,000 ft. where the thin air dramatically impacts maneuverability of an aircraft. The F-22 is one of the few aircraft able to operate (not just fly) at this altitude and the reason two Raptors belonging to 1st Fighter Wing at Langley were scrambled for this mission early on (February 1) from Nellis AFB where they were deployed for Red Flag 23–1. Using the gun would have required the Raptor getting around 500 meters to the target which combined with the altitude and nature of target posed an unnecessary risk.
‘So, you had the USAF using the next best ‘low cost’ solution, an AIM-9X from F-22 operating at 58,000 ft. instead of an AMRAAM. The fragmentation warhead of the missile caused enough damage to significantly destroy the balloon’s structural integrity and quickly leak vast majority of helium resulting in the balloon falling immediately instead of drifting apart. And the F-22 could launch AIM-9x several kilometers from the target, negating the risk of debris field.’
Sengupta concludes;
‘While using the gun would appear as a more cost-effective solution for such a shot-down, in reality it’s not only ineffective but might as well be a far worse solution. And frankly, at $380k AIM-9X is pretty cheap as far as Military Aviation goes.’ At this point one may ask if a high-altitude balloon is “hot enough” for a heat-seeking missile like the AIM-9X.’

Andy Burns, former US Navy Surface Warfare & Naval Flight Officer, explains on Quora;
‘Modern infrared-seeking air to air missiles – and the missile used in the balloon downing was reported to be an AIM-9X, which is the most advanced Sidewinder variant in US service – have extremely sensitive seeker heads. They no longer need to “see” something as hot as engine exhaust in order to track a target, as did early models. They only need some infrared contrast, and up in the 50K’+ altitudes where the balloon was reported to be, just about anything man made is going to give off more of an IR signature than the surrounding air.’
Photo credit: U.S. Air Force and USNI News

So how is it possible that it would muss the balloon the first time?