Why are the teams in groups in the world cup?

Each group will play a round-robin style tournament with the top two teams from each group advancing to the knockout stage.