Materials with reduced dimensionality often exhibit exceptional properties that are different from their bulk counterparts. Here we report the emergence of a commensurate 2 $times$ 2 charge density wave (CDW) in monolayer and bilayer SnSe$_2$ films by scanning tunneling microscope. The visualized spatial modulation of CDW phase becomes prominent near the Fermi level, which is pinned inside the semiconductor band gap of SnSe$_2$. We show that both CDW and Fermi level pinning are intimately correlated with band bending and virtual induced gap states at the semiconductor heterointerface. Through interface engineering, the electron-density-dependent phase diagram is established in SnSe$_2$. Fermi surface nesting between symmetry inequivalent electron pockets is revealed to drive the CDW formation and to provide an alternative CDW mechanism that might work in other compounds.