The only problem with alexhu's suggestion is that it will return anyone who has a group ID the same as the user ID you're looking for.
If you set $TARGETID to the uid you want, I think this will do the trick:
awk -F : "\$3 ~ /^$TARGETID$/ { print \$1 }" /etc/passwd
Actually I think uids can be shared, which seems like a bad idea to me, but you may want to account for the possibility of more than one result.