Yeah, に can have that "as" meaning like in sentence one there. In the second, however, it does not have that meaning. It might be a little confusing, but only if you try to attach one meaning to each particle. に has many different uses. In fact, it has at least 15 distinct definitions. Here you're dealing with definitions 8 and 3 respectively (I'm pretty sure, anyway).
The fact that there are many ways to use に may seem confusing, but generally context and a more thorough familiarity with sentence patterns and how it is usually used will be more than enough to know the correct interpretation. Just treat it like any other homophone.
If you really want to break に down to its purest essence and not just take the many meanings for granted, there are some general categories you can break it into that some of the definitions could be grouped into.
For example you have the に of location, which describes where something is. For example, 本は机の上にある. You have the に of literal or perhaps metaphorical direction, a category in which I would include sentences like スーパーに行った and 友達にプレゼントを上げた. You have a に that represents the agent in passive constructions, like in 男に殴られた. You have the に that determines something's role, what it is and the purpose it serves, as in your おみやげにチョコレートをもらった. You have the に that marks the way something is done, as in with adverbs, like 嬉しそうにケーキを食べた. There are probably more, but I think this illustrates the point. These are all distinct and have obvious applications and are easily understood within their respective contexts.
So does it get confusing? Actually, it doesn't really. Not usually, anyway. Of course you can always find examples of ambiguous sentences, but that doesn't mean communication in general is difficult, even in longer sentences. You'll have enough hints based on the words in the immediate vicinity of the に to understand what's going on.
Look, for example, at your sentences. You wonder if 先生に友達を紹介した could be interpreted in such a way that the に in this sentence is saying what your friend is, i.e. a teacher, like in the omiyage sentence. It is true that に used like this can mean the same thing as として, in which case it would be as you thought. But when used with people it does not have this meaning. As such it is unambiguous. I cannot think of a context in which someone could possibly interpret it the other way (any native speakers can chime in here if they would like). 先生に友達を紹介した deals with humans, so its meaning is set.
As for the alternative ways to say it, I'm a little unsure at the moment with regard to the exact nuance that you're trying to convey in English, but here are some ways you can say it in Japanese.
You could say 先生である友達を紹介した. The nuance of this one is that you introduced (to someone) your friend, and incidentally that friend also is a teacher. The emphasis however is that you introduced your friend.
Next, you could just say 先生の友達を紹介した, which has a similar meaning to the above.
Another way that I think gets more to the heart of what you want is to turn the に overtly into a として and say 先生として友達を紹介した. In this case, you would be saying "I introduced my friend as a teacher" in the way I think you mean, where the person is your friend, but in this situation you emphasize the fact that he is a teacher. You can switch it around as well to say 友達として先生を紹介した.