The principle in using ad-libbed lines and spontaneous off-the-cuff lines as possible new material is: If friends or an audience laughed at the line once, you might get laughs with it again.
Here's another aspect to that principle. The lines your audience members ad-lib during your speech can often be used again. This is a superb way of gathering new, already tested humor. Now this works better for the professional speaker than it does for the professional performer (comedian, magician, ventriloquist, etc.).
With performers, too often the audience line is intended to upset you or upstage you. And while that may happen occasionally in a speaking situation, more often than not, an audience member had simply gotten caught up in the spirit of things and is participating in a humorous way. And those lines can be pure gold. They are more valuable than ones you ad-lib for three reasons.
You can sometimes simply insert the line in your speech / presentation somewhere. Other times you might tag the line by saying, "Well, in one of my previous workshops / presentations / speeches, one of the audience members said..." and then quote the line.
One caveat about audience humor. Sometimes audience members will come up to you afterward and share a bit of humor with you. Often they will say, "You can use that if you want." This can sometimes also be a source material, but it can also be a source of humor that can backfire or embarrass you. You will learn how to avoid this in Your best source of new material - But Beware!