According to our current models of the universe, just after the Big Bang, only a few elements were in existence; hydrogen, helium, and a little bit of lithium. These are the three lightest elements in the periodic table, and it’s the main reason why astronomers can get away with calling everything that’s not hydrogen and helium a ‘metal’. (Don’t tell the chemists. Or the physicists.) Effectively, we can think of everything heavier than those two as contaminants on the primordial batch of gas that we started with.
These heavier elements are really useful tracers of a different astrophysical process; stars. Heavier elements are exclusively made either in the cores of stars, or in the end-of-life supernova explosions of very large stars, if the element is heavier than nickel. As a fun corollary, it means that all the lead and gold we find on our planet is the direct byproduct of a star exploding somewhere, many billions of years in our past.
Iron and nickel are both formed in the very centers of large stars, at the very end of their lifetime. Nickel can be formed through nuclear fusion (the same process that fuels our sun), but the form of nickel that is produced is unstable, and decays into iron relatively quickly – iron is often quoted as the heaviest element that a star can produce. All of the stars which are capable of creating nickel and iron go through a supernova as their dramatic end to life as a star – the supernova is triggered when nothing remains in the core of the star that can be burned. The burn that creates nickel is the very last one possible, so a supernova is imminent once this process starts.
Conveniently for the spread of metals, supernovae are pretty sizable explosions, and will spread some of the elements they’ve created into interstellar space. (Some fraction of these hard-won elements will stay stuck in the remnant of the star – a neutron star or black hole, at the stellar masses which can make iron in the first place.) Over many generations of stars, the small amounts of metals that have been created and dispersed build up, to the point that any given gas cloud has probably been filtered through a star at some point in the past. There’s some metal content already in the gas before anything else happens to it, just because it’s already gone through a few rounds of stars. So it was with the cloud of gas which became our solar system – the gas already held a good amount of nickel and iron, and all the other elements we now spot on our planet.
As the planets began to form, heat from impacts and other sources melted the existing rock, and, since iron and nickel are very dense materials, it is the iron and nickel which sank to the cores of the rocky inner planets during differentiation. (Differentiation simply refers to the process by which planets ordered their interiors, as the most dense materials sank to the center.) So it’s not that the nickel and iron are produced in this settling process – the settling just collects it together. Those nickel-iron asteroids are, as you say, either material which didn’t collect properly, or was in an object which was trying to become a planet, but then broke apart. But the nickel and iron itself was forged in the very core of an ancient star.