The Bible tells the stories of many people. Many of the characters–real people who really lived–are exposed as spiritual failures. Some readers would no doubt prefer that the Bible included only success stories, but there is a reason that God allowed these failures to be written down for us:
These things happened to them as examples and were written down as warnings for us, on whom the culmination of the ages has come (I Corinthians 1:11 NIV).
The simple matter of the fact is that warnings are better teaching instruments than praise. Human beings learn more from seeing something done wrong than seeing something done right. When we see somebody do something right we criticize them anyway, just out of spite, imagining that we ourselves could do things better. But when we see someone do something wrong we try to avoid their mistakes. Praise makes us arrogant, rebuke makes us wiser (if we listen to it).
The Bible, of course, has both praise and rebuke, but it is very heavy on the rebuke. We need to humbly learn from these failures, and not make the same mistakes that they did. My Dad always told me that it was better to learn important life lessons from the mistakes of other people than to make the same mistakes myself. He is absolutely right. The Bible does not record these mistakes because they are inevitable, but rather, because they can be avoided, and, by reading with a humble heart, we can learn how to steer clear of them.