You need not return to your home country to file Form I-485 for adjustment of status and this immigration process is meant for the non-immigrants who are already in the United States and who are eligible for lawful status in America. If you manage to get a sponsor in the United States while in the country as a non-immigrant, you may go for adjustment of status as this process will permit you to become a lawful resident and you may not be required to go to your home country to apply for adjustment of status. However, you may not qualify for adjustment of status if you are in a foreign country and in this case you need to go through a process called consular processing.
Only if you are already in the United States and if you are eligible for a US Green Card through family or employer sponsorship, you can file Form I-485, Application to Register Permanent Residence or Adjust Status, for adjustment of status and in this case, you need not apply for an immigrant visa. If you hold a valid non-immigrant US visa and if your relative or a US employer sponsors you and files an immigrant petition for you, you may apply for adjustment of status after the immigrant petition is approved. This is a process through which you can get a Green Card while in America.
For some family based categories, visa numbers will always be available and if you belong to one such category, you may file Form I-485, while your family member files Form I-130, Petition for Alien Relative, for you and you need not wait until the USCIS approves Form I-130. But if you belong to some other category, you will be put in waiting lines and you may file Form I-485 only after a visa number becomes available. You may also apply for adjustment of status, if you have been living in the United States as an asylee or a refugee for a year or more. After your petition for adjustment of status is approved, you will be granted lawful status.
But you need to remember that, you can apply for adjustment of status, only if you are in the United States and you need to go though consular processing if you are abroad. If you are abroad, you will have to apply for an immigrant visa in a US Consulate in your home country and then travel to America with that immigrant visa. If you leave the United States, while the immigrant petition filed on your behalf is pending, you cannot apply for adjustment of status and you will have to apply for an immigrant visa and wait in your home country until your petition is approved. Adjustment of status process will permit you to adjust your non-immigrant status to immigrant status and obtain a Green Card. Hence, you need not leave the United States, to file Form I-485.