If you invest in a 401(k), the shares in that plan are yours for as long as you live, or until you pull them out. So, if the employer is offering any sort of matching and those matched funds remain yours after you leave, then definitely contribute; that's an immediate return on your money. If the employer is NOT matching funds, then usually it is better to contribute to an IRA instead; you get the same income tax benefits from the deduction, without the headaches of going through your company (or the company from 3 jobs ago or whoever bought them) to get to your money.
If I were in your position, the most I personally would do after I quit the company (which I'm assuming you'd be doing if you were going back to your country of origin) would be to have the 401k shares rolled over into a traditional IRA; that way I'd have more control over it from outside the country. Just keep the bank holding your IRA apprised of your movements around the world and how they can get ahold of you (it may be wise to grant a limited power of attorney to someone who will be staying in the U.S. if you don't want the bank mailing your statements all around the world), and the money can stay in an American account while you do whatever you have to outside it.
As long as you don't take the money out in cash before you're 59 1/2 years old, you don't need to pay taxes or penalties on it. If you were to need it to cover unexpected expenses (perhaps relating to the aforementioned family emergency), then that decision can be made at that time. If you think that's even remotely likely, you may consider a Roth IRA. With a Roth, you pay the income taxes on your contributions, but the money is then yours; you can withdraw anything up to the total amount of your contributions without any additional taxes or penalties, and once you hit 59 and a half the interest also becomes available, also tax- and penalty- free. So if you had to leave the country and take a lot of cash with you, you could get out everything you actually put into a Roth with only minor if any transaction fees, and the interest will still be there compounding.