What is the origin of the custom to kiss the Mezuzah, or a Siddur or any other Sefer?
The Mezuzah comprises two Parshiyot. The first begins with "Shma Yisrael" and is found in V'Etchanan and the second is "V'Haya Im Shamoa Tishmeu" which is in Parshat Eykev. (Both in Sefer Devorim) In the Mishna in Masechet Brachot, we find a definition for each section; the first is declaring our loyalty to the G-d of Israel and the second is acceptance of Mitzvot. Each time we enter or exit a home, the Mezuzah reminds us of the holiness of these Mitzvot and the love with which we perform them. So it is only natural to express our love by kissing the Mezuzah. Likewise, we express our devotion and love for the contents of holy books by kissing them when we put them aside. Rabbi Eliezer Waldman