Can I ask a professor to do work for him/her during the summer as a form of an internship? I am a newly transferred undergraduate Earth Science major and because of this I haven't had any internship experience in my field, even though I will be going into my senior year this fall (I also might have to take an extra semester to make up for time lost). 

In my previous major, I remember my advisor saying he had a student who just filed data for him all summer for free, and at the end he gave her a letter of recommendation and she put it on her resume. It seemed like a kind of informal internship, and since I'll be taking a summer class, the casualness of it seems preferable as a way of getting some experience, as compared to a rigorous 9 to 5 internship that will take up all of my time. So my question is, could I simply email professors at different universities close to my hometown and ask if they need any help with their research this summer? I would prefer to ask my professors at my University, but because I'm taking  a summer class in my hometown (about an hour away from my University) I wouldn't be able to drive everyday. 

I feel like professors who do their own research would want all the help they can get, like someone to do grunt work, which I would be fine with as long as I can get something to put on a resume and/or a letter of recommendation for a better internship/job down the line.
You can certainly send emails to faculty offering your unpaid services over the summer. This is common practice.

When you do, keep in mind that professors often receive numerous such offers and that, depending on the nature of the lab, the cost of getting a volunteer or intern up and going may exceed the benefit of having the volunteer around.  Moreover in some areas, particularly more mathematical and theoretical disciplines, an intern would need considerable background in math, programming, or similar to be of much service. 

Therefore it is strongly in your interest to make your offer stand out from the others. One way to do this is to convey a decent understanding of the work being done in the lab to which you are applying, and to convey your interest and enthusiasm in being part of that work. When I receive internship requests where the writer has expressed no interest in my work and has simply pasted my name into a form letter, I invariably decline. (Even worse the ones that paste text directly from my web page into the part of the letter describing their research interests -- it happens more often than you'd think!). 

Another important way to improve your chances is to use your understanding of what goes on in that lab to very explicitly describe some ways that you be might be able to provide valuable service to the lab. If they sound like they need programmers and you are a good coder, for example, make this very clear.