You'll need to explore the AutoDesk DWG file format. A great place to start would be here which attempts to document the data specifications of AutoDesk's undocumented format:
http://www.opendesign.com/files/gues....dwg_files.pdf

Using that, then you take your graphic information and write a properly formatted DWG file; since all a file is, is just a big lump of ASCII and/or binary data formatted in a special way.

The trick is, creating that lump of data. When I've had to do it in the past with a complex file format, I realized from looking over the documented specifications, that I wouldn't need to worry about 99% of the data in my file, all I needed to do was to take an empty, generic file with all the default data in it, and insert my custom data into it in a specific format at a specific place. Thus, I "saved" an "empty" file (like saving an AutoCad file with no lines or elements), and opened and modified that with my program to insert my data. To test it, I then tried to open my modified file back in the native program and if it complained it couldn't read the file or the file was corrupt, I knew I did something wrong. When it finally did read back my file with the additions I inserted into it, I knew I had a winner.