Yes, They have the same meaning.
There are some additional comments I gotten from other forum as following (translated from Chinese):
The core element of the sentences is "我写信", the object of writing is expressed in different ways. Example 1 is before "写信", it is adverbial; Example 2 is after "写信", it is a complement. Both are correct.
The ambiguity of Example 1 is come from the diffrent meanings of "给", not from the sentence structure.