What is the reason for the Earth to behave like a bar magnet and have poles (North and South poles)?
The Earth's magnetic field is caused by eddy currents in the liquid parts of the planet's interior. We believe the field is not due to a permanent magnet because: (1) Its direction and strength change over time, and (2) the planet's interior is hotter than the Curie temperature of its elements, and so a permanent magnet would not retain its magnetism. However, saying the field is due to eddy currents is not sufficient. Simply swirling around a conductive fluid does not produce a magnetic field. There has to be some source of electric current to make the whole process work, and we don't know what that source is. Several possibilities have been proposed. Examples include: (1) Gravitationally separated elements produce a voltage difference, as in a battery; (2) Gravitationally separated elements combined with the temperature differential between the Earth's core and its mantle creates a thermocouple junction that produces voltage, and therefore current; and (3) Flowing electrons produced by Beta decay of radioactive material in the core. However, none of these explanations are accepted as proven, and some are thought to be highly unlikely. So the source of the electric current remains a mystery.
When we say that the Earth's field behaves "like a bar magnet", we have in mind a field that is approximately dipolar. So while it is true that a geodynamo powers the field (see this Wikipedia page), we need to say a little more. First, the rotation of the Earth organizes the flow, tending to align it with the rotation axis. Second, the magnetic field from a finite source looks increasingly like a dipole as we get further away from it; in a multipole expansion, the higher the order of the term, the faster it drops off. The surface of the Earth is at a radius that is roughly twice the radius at the core-mantle boundary, enough distance for a substantial reduction in non-dipole contributions (see Merrill and McElhinny, "The Magnetic Field of the Earth: Paleomagnetism, the Core, and the Deep Mantle", Academic Press 1998, chapter 2). Finally, the magnetic field in the core could have a large toroidal component, but we know little about its strength because toroidal components don't pass the core-mantle boundary (Merrill & McElhinny chapter 9.2).