Origin of Vertical Orientation in Two-Dimensional Metal Halide Perovskites and its Effect on Photovoltaic Performance