How do scientists know how the earth was created?
They use known information and theories that are supported by some evidence to try to make reasonable explanations.
Earth formed about 4.6 billion years ago along with the other planets in this Solar System.
Heavy elements (those that are present in the current Solar System) had to have been formed by then, perhaps as a result of a pre-Sol supernova (where Sol is the name of the star at the centre of this Solar System, also known as the Sun). \
The heavy elements would have accumulated together via gravity. The larger the collection of elements, the more would have been attracted (the greater the mass, the greater the gravity).
The collection would have continued via gravity, forming stones, then boulders, then meteor-sized objects.
The coalescence of these meteors would have formed items as massive as planets, such as the Earth.
This is the story science has managed to envisage so far.