About writing the USMLE outside the USA: The exam can definitely be written outside the US but not all steps. For the ones you can write outside the USA, Ghana and South Africa are potential centers.
There are 3 USMLE steps but 4 exams in total, though you need only 3 to apply for residency: Steps 1, 2CK and 2CS. You can write Steps 1 and 2CK outside the US but Steps 2CS and Step 3 have to be written in the US. You can write them in any order.
Remember that you will still need a US visa to come and write the other exams. This is where you need to consider your options for getting into the US. As I said, you do not need step 3 to apply for the residency program. Step 3 is typically written during the residency program.
IMGs can, however, write the exam before residency so you can apply for a particular type of visa (H1-B as opposed to the J1). That is a totally different discussion for another post.