As the solar system formed, why didn't all of the heavier elements such as iron, collect where the sun is leaving the lighter elements in the outer solar system?
That is actually somewhat the case...
The planetesimals formed in the inner Solar System were rocky planets (our terrestrial planets evolved from these), whereas the outer planets (the gas giants) in the cooler zone evolved from lighter elements such has hydrogen and helium.
This is of course an incomplete answer. From exoplanets surveys we have found many systems with inner gas giants. There are many aspects we are yet to fully understand about the evolution of these systems. Such aspects could be planet migration, long term tidal effects (affecting orbital energy) and impact events.
Most of the iron and heavy elements in the solar system are in the Sun.
They aren't all in the Sun, because the material from which the solar system formed was well-mixed and turbulent.
The reason that the concentration of heavier elements is higher in the small, rocky, inner planets (the gas giants have an abundance mixture similar to the Sun), is that firstly, only heavier, "refractory" elements could condense into solids in the hotter inner parts of the protosolar nebula; and secondly, once these had clumped to form protoplanets, they were unable to capture and hold onto the vast amounts of hydrogen and helium in the early protoplanetary nebula, because of their low gravities and high temperatures.
The sinking/diffusion you refer to requires, stratified, stable fluids. This condition was not satisfied in the proto-solar-system, but was satisfied in the early history of the planets; hence the ample evidence for chemical differentiation in most of them, with heavier elements sinking towards the middle.
This question is tantamount to asking why do stellar systems, galaxies, and even planet-moon systems have a spatial extent as opposed to forming centralized blobs of decreasing density radially. The answer lies in the fact that all these objects have a rotational motion that spreads the mass outward, with the occasional accretion of heavier elements happening further away from the center of rotation. The chaotic nature of that accretion generates "islands" along the radius where heavier elements can indeed form enough critical mass (and thus rotational inertia) so as to not end up at the center.