I remember hearing a while ago that sawdust and wood glue can be used as a wood filler to fill in gaps and imperfections.
Yes you can do this, but note that the term "sawdust" might be slightly misleading here. Commonly when this sort of thing is done at home it uses sanding dust, not actual dust from sawing which would tend to have a range of particle sizes including some much coarser flakes and generally you want the filler dust to be as fine as possible.
I would buy proper wood filler but I would rather not spend the money and I am also curious if this technique is realistic.
Actually in a lot of ways I think you're better off not buying wood filler. Most commercial wood fillers are slightly disappointing in some way and if you have a ready supply of wood dust already it is a good way to make use of at least some of it.
Also how might this effect finish the piece, if I was to stain the wood would the filler stand out and be very obvious?
If you stain the piece yes it will tend to stand out, usually very obviously.
Most fills made from wood dust and adhesive (including epoxy, white and yellow glues and superglue) are not absorbent and will therefore stand out very noticeably if you then stain, since that relies on absorbency. So an alternative approach used historically was to stain first and then use a filler that matched the stained colour (or often one shade darker), although unfortunately this approach isn't generally practical with glue + wood dust fills because of the need to scrape or sand the filler flush.
If you're not staining
You will at some point read online that if you make a filler from the dust of the same species as the wood you're working on that "It's a good colour match." and even sometimes that "It's a dead-on match." but I can tell you that in most cases those are lies or the person writing is being too generous!
In almost all cases the fill will be significantly darker than the surrounding wood. The reason for this is that the dust has been wetted by the glue so it's behaving quite like end grain, which when wet shows up darker than face grain.
This is one of the reasons to not buy commercial wood fillers by the way, because even the "stainable" ones tend not to take stain that well.
There are a few formulas posted online for DIY fillers that stain far better than any of the commercial versions according to their users. Most include some plaster or spackle in the mix to increase absorbency.
But on a smaller scale if you use sanding dust from the same species and hide glue as the binding agent you can get a very reasonable colour match that isn't obvious from arm's length and occasionally even closer. Such a filler can even have good staining properties, but the type of stain you use will matter so no guarantees here and you'll need to experiment for yourself.
Further related info:
Large hole filler products, what is available