In this paper, the effect of H2O on the microstructure of block TiO2 (b-TiO2) and PbI2 films during spin coating for perovskite solar cells was investigated. Dense TiO2 and PbI2 films were formed in a N-2 glove box regardless of the spinning time; in contrast, porous TiO2 and PbI2 films were formed in a humid atmosphere. The formation mechanism of the porous TiO2 film was suggested to be a sol-gel reaction resulting from the reaction between the wet-state alkoxide film and water molecules in the humid environment during spinning, whereas a TiO2 xerogel structure was formed without the sol-gel reaction in the non-humid environment. In addition, it was suggested that the porous PbI2 film was formed via a reaction between the wet-state film and water. In conclusion, control of the reaction between the coated wet film and water molecules was important for coating optimized b-TiO2 and PbI2 films.