Money is convenient because it can function as a means of exchange.
The guy could have bought an apple very easily if he had exchanged his pens to money which everyone uses for every kind of businesses.
Money is also useful to measure the value of goods. It is not sure that 10 pens for 1 apple or 5 pens for 1 apple?
Thus, it is convenient to use currency to measure how much a pen and an apple cost. The value of goods becomes stable so that everyone can have fair business.
In barter business, not only pens and pineapples, but fish, livestock, vegetables,, everything has to be exchanged.
What if foods go bad or goods are fragile?
You can keep their value if you exchange to currency.
For example, the guy had 1,000 pineapples. He cannot eat all of the pineapples. Weeks later, of course the pineapples will go bad and he had to waste them.
To summarise, money can be used as a (1) medium of exchange, (2) unit of measure, and (3) store of value.