Such a fun question, because it has such a fun answer! Mary Shelley and her husband, Percy Bysshe Shelley, were visiting their friend Lord Byron when she got the idea for this book. The three friends agreed to challenge: who could come up with the best ghost story to scare the other two? Shelley wrote in her introduction to the book that she was inspired by the image of a ghoulish and "hideous phantasm of a man".
The image became Victor Frankenstein's monster. Shelley used the technique of horror stories that would later become central to the writings of such authors as Stephen King - base the tale as much on real situations as possible. Science was beginning to encroach on everyday life in Shelley's world, in the early 19th century. Just as we can imagine hover cars being a possibility, it was not a far leap for people of the time to imagine science had the capability to reanimate life.
Which leads to Shelley's other purpose in writing. Like many of the romantic authors, Shelley wanted to idealize and glorify nature. She creates this story to demonstrate negative affects of science and of man's attempts to control nature. She makes the tragic flaw of her protagonist his arrogance in all dealings with the natural world.
And all from a friendly bet!