How do you root safely? I am thinking of rooting my android.

In general, it seems that one downloads the "unlocked" firmware from a website (not the manufacturer's) and then runs it on the phone.

How do I know if that firmware is safe (in other words, how do I know if the "rooted" firmware doesn't have a keystroke logger, for example)?
It all depends on trust. Go to http://forum.xda-developers.com and search for your device. There are high chances your device will have a separate thread on rooting. Read the entire discussion and try to root.

Just remember one thing, always backup before doing anything. The thread will, most probably, contain a guide to backup your factory image too.