Why does the Huffman coding algorithm produce a valid tree?
Let $v$ be a vertex of the tree. If $\pi_v$ is the path from the root of the tree to $v$, then the string $s(v)$ constructed from the labels of $\pi_v$ is unique (if you really want, you can prove this by induction on the depth of $v$).
If $s'$ is a proper prefix of $s(v)$  then there is a node $u$ in $\pi_v$ such that $s(u)=s'$ and, by the above observation, this node is unique.  Moreover, $u$ cannot be a leaf (since it precedes $v$ in $\pi_v$).
This means that, for each leaf $v$ there is no prefix of $s(v)$ that matches the code $s(v')$ of another leaf $v'$. Since the symbols only appear as leaves of the tree, this means that the code is not ambiguous.