There is no answer to such general question, each event that generates refugees has its own causes and explanations. Maybe a common answer could be that well-being of people is given far less importance than particular interests of powerful and those who want to become powerful. Creed and grievances.
The basic reason is the 'security' in terms of food and shelter, as you mentioned and everybody considers. However, the root is always the politics and the leadership that make any place not 'suitable' to the people as per their aspirations- thus becomes 'refugees' of different typology.
My grandfather fled Russia in 1922, taking his family with him. Since he had fought for the Tsar, the new government did not like his politics. Many refugees leave their countries because of wars, revolutions, religious or political persecution, famines and crime. The fact is that happy people don't flee. If you are in danger or miserable, you just might.
Básicamente el primer objetivo es la supervivencia. Evitar la violencia, el hambre, persecuciones por otras ideologías tanto políticas como religiosas. Hay que tener en cuenta que estas personas huyen ya que su propio gobierno no se preocupa por las condiciones de la población. Es una manera de estar más seguros. Aunque no hay una respuesta clave, cada persona tiene sus propios motivos.