The answer is simple: “Men spoke from God.” But how did they know what to speak and what to write? The quoted, from the apostle Peter, goes on to explain that they spoke as they were borne along by holy spirit. (2 Peter 1:21)
You see many of the Bible writers did not know one another. They even lived centuries apart and were extremely different in temperament and experience, as well as in social and educational backgrounds. Yet, whether they were young or old, their writing shows a complete unity. Over a period of some 1,600 years, they wrote until the book was finally finished. You can take a careful examination, and find that the Bible’s statements reflect a remarkable harmony. So Bible thus echoes the mind of one Author, though many writers were used.