The quote you refer to is from Shakespeare's play entitled, Hamlet.
The speaker is Polonius who is King Claudius' trusted advisor. Ironically, Polonius gives wonderful advice, but finds it impossible to take it himself. (His son Laertes is also one to give advice, as with his sister Ophelia, but she is not too quick to agree unless he accepts the wisdom of his words and follows his own advice.) In fact, his behavior in being an advisor to the King, is difficult to understand: Polonius is a windbag. At one point, Gertrude almost has to tell him to be quiet ("More matter, less art!") because he rambles on and on about nothing important.
Much of the best advice in this play (and many of the quotes) come from Polonius. His words almost sound as if they could be found in the Bible or in writings by Ben Franklin in Poor Richard's Almanac, but they belong to William Shakespeare.
Regarding your quote, Polonius delivers this counsel to his son as Laertes is preparing to take his leave from his family. Polonius has good things to say. One is "Neither a borrower or a lender be." The location in your version of the play may be slightly different in terms of the line numbers, but the act and scene will be the say.
Look in Hamlet, Act One, scene three, line 79.
Neither a borrower nor a lender be,
For loan oft loses both itself and friend,
And borrowing dulls the edge of husbandry.