Would the gravity of the Sun have drawn it so close? Or was its trajectory, narrowly missing the Sun, a coincidence? Must be the former, I guess, with its mass/speed too great to be drawn into the Sun completely.
Yeah, its the Sun. A tiny perturbation from random interactions with other bodies set it inward toward the Solar systen with a small velocity and from then on the Sun's gravity does the rest.
The trajectory is characteristic of bodies that are attracted gravitationally from far away but gain too much kinectic energy to remain bound in orbit, so they escape and never come back.
For the science: we've used gravity assists to increase the speed of rockets. That's how we got Voyager out of our system. This 'comet' (that's just bug PR for this near miss) did the same.