I was on a student visa in the UK, but now I am going back to the US and am trying to figure out if I am allowed to freelance for the company that I had interned for in the UK while living in the US.
It is perfectly acceptable to work from the US for a UK company.
You will need to invoice the UK company from a US entity (either Inc or self-employed), paying the taxes at a state and federal level in the USA. You should call your state's small business administration (sba.gov on a federal level) and ask for advice on how to get set up.
The regulations that tend to apply are typically guided by where the work is performed. Since you would perform the work in the US, then you are applicable to US laws (thus ensure you register yourself appropriately there in order to raise an invoice to the UK company). If you think of it, the relationship would be no different than the call centers in India who serve the UK (or other places in the world).
It's important to make clear that you would have to raise an invoice in order to be paid - you would not be an employee in receipt of a salary from the UK company. US taxes would be your responsibility. The UK entity might ask for evidence that you are registered (even if just a copy of your passport) so that when they pay your invoice, the UK taxman can be somewhat confident that your invoices are legit in the event of a UK HMRC tax audit.
Yes, you absolutely can! I live in the US and freelanced for a company in Australia. The only thing is that because they are not in the country, they are not required to send you any kind of tax documents, and come tax time you will have to pay taxes on all your income for the year. The plus is that you can also deduct your business expenses. My best advice for you is to keep a copy of all invoices you send to the company, all payments they send, and receipts for the year and consult a tax professional when it comes time to pay taxes. Also, if you can afford the expense, consult an accountant who can help you estimate taxes and even pay your taxes quarterly so you don't have a huge chunk to pay come tax time. Alternatively, just make sure to put about 20% of your pay into a savings account so you have the money to pay. This is saving more than you really need to, but this way you know you have enough to cover it instead of having to scramble to find the money.