Context is all.
You have made the leap from a teaching aid
"a pen to write" is incorrect and that you need to say "a pen to write with"
I will assume what your teacher was saying, was
"I need a pen to write" is incorrect and that you need to say "I need a pen to write with"
Thus associating the pen with making marks on paper. This is one piece of information.
Fast forward to
You don't unwind the bar but you unwind in the bar, don't you?
When you look at the sentence you need to observe the context in which it is written.
The bar is a favorite of the locals to unwind after work.
your should now automatically separate that into two pieces of information
The bar is a favourite of the locals
Because two sentences have been combined to make this sentence we also know that it has elements that are common to both pieces of information "The Bar and The Locals"
(locals like) to unwind after work (in this place)
From the context we know they like this place because it is a favourite. We also know they are in the bar when they are relaxing, because it is the fact they are here that causes them to relax.
unwind verb (RELAX) CED (also wind down)
to relax and allow your mind to be free from worry after a period of work or some other activity that has made you worried:
It easy to comprehend the link between pen and writing but to comprehend the thought process of physically unwinding a bar takes a lot of comprehension.