Until life became organized into the two main cell types we see today, prokaryotic and eukaryotic cells, molecules like nucleic acids (the building blocks of DNA) and amino acids (the building blocks of proteins) were free-floating in the environment.
While some free-floating molecules were self-replicating, the organization of molecules into cells with internal structures that performed specific tasks made the first single-celled organisms more efficient at reproducing and surviving under early conditions on Earth.
Increasing efficiency with increasing organization means that natural selection would thus have favored the development of cells that perform specialized tasks.
Prokaryotic cells are the simpler of the two basic cell types. In a single-celled prokaryotic organism, like an amoeba, the cell is the organism. Prokaryotic cells are smaller and simpler than eukaryotic cells.
In an organism with eukaryotic cells, like humans, cells perform specialized functions. For example, red blood cells carry oxygen throughout the body and B-cells help the immune system ward off pathogens.