The correct answer is **B. I and III only**.
Here's why:
- **Statement I** is correct: The early stages of solar system formation involved the collapse of a fragment of an interstellar cloud under the influence of gravity, leading to the formation of the solar nebula.
- **Statement II** is incorrect: The planets did not originally orbit a nearby star. Instead, they formed from the material in the solar nebula that surrounded the young Sun.
- **Statement III** is correct: Gravity played a crucial role in the process of accretion, allowing small particles in the solar nebula to stick together and form larger and larger bodies, eventually leading to the formation of planets.
- **Statement IV** is incorrect: The gravity of planets did not pull the Sun away from a nearby star cluster; rather, the Sun formed at the center of the solar nebula.
Thus, the statements that correctly describe the role of gravity in the formation of our solar system are I and III.