I believe the story of Job was recorded so that all future believers that were suffering hard trials could know the truth against all the lies that would come at them, that God has turned against them, etc. and that is why they are suffering. This is what Job's friends told him, and we get to see how all that played out. They were very wrong, just as all the future "Job's friends", the "miserable comforters" as Job called them, would be very wrong!