Why did pope Gregory and Henry the fourth come into conflict

In the 11th century, the Investiture Controversy arose between the papacy and the Holy Roman Empire. Pope Gregory VII believed that the pope, as God's representative on Earth, should have full authority over the appointment of bishops and other church officials, while Emperor Henry IV of the Holy Roman Empire believed that the church should remain under the control of secular rulers, including the emperor. This conflict eventually led to years of war, excommunication of Henry IV, and the eventual resolution of the issue through the Concordant of Worms in 1122, which recognized the pope's authority in spiritual matters and the emperor's role in secular affairs.