What return you must file, as well as when and where you file that return, depends on your status at the end of the tax year as a resident or a nonresident alien.