How did the endoplasmic reticulum come to be?
Found the following on wikipedia. Seems pretty self explanatory:


  The Golgi, ER, and lysosomes are likely to have evolved as a result of
  the plasma membrane going through invagination. An increase in the
  overall volume of a cell would require the plasma membrane to fold in
  order to maintain a constant surface area to volume ratio. These folds
  may have led to the specialization of internal membranes to maintain
  communication with the environment. In the first stages of eukaryotic
  cell life, the membranes may have been interconnected and attached to
  the plasma membrane. Later on, as their functions diverged, the
  membranes may have become separate structures