The みたい and に I'm referring to here are from a song called Don't you see! The first two lines of the lyrics are:
友達に手紙を書くときみたいに
スラスラ言葉が出てくればいいのに
If I understand it correctly, the に is used to link the two lines. But I'm not sure what kind of grammar it is. Although there is a grammar that a な-adjective can be converted to an adverb by appending a に to it, the みたい doesn't seem to be a な-adjective.
P.S. Here is the shorter version of the song, if by any chance it can help interpreting the meaning: link.