What do I do when I have a little filament left?
Heat the extruder up first, then remove the filament. You can remove the filament either by reversing the extruder using a command such as G1 E-100 F200, by using your printer's controls/LCD (if it has one) or simply pull the filament out by hand. To this end, most extruders have a lever that you can push to disengage the drive gear to make it easier to pull the filament out.

You can just heat the extruder up to printing temperature, but a perhaps better approach is a cold-pull, where you heat the extruder up just barely enough to be able to remove the filament (to, say, 120-180°C) and then pull the filament out. This has the advantage of removing more of the old filament and perhaps also taking some debris that may be stuck in the nozzle with it.

Trying to print it all out won't work because once the last bit of filament goes past the drive gear, you won't be able to extrude the rest of it. Feeding in a new bit of filament might push the old filament out, but it could just as easily get jammed.