After the sun and planets formed, there were chunks of material left orbiting the sun, which were asteroids.
The reason they are floating around and not pulled in by another planet is because they never were close enough where the would be sucked in by the planets' gravity.