Was the story Hebrew in origin? Would it have been intended as a metaphor for the people undergoing a period of suffering, and to encourage them not to turn against God, or was it adapted from another culture? Would it have been written to encourage personal piety, or to argue for a worldview in which suffering is random and not sent from God as a punishment for wrongdoing?
This response addresses the questions you raised as to the purpose of the Book of Job.
My personal opinion is that the Book of Job is demonstrating the human struggle to deal with his own self righteousness. Job was hugely self righteous. That was the specific issue that God was dealing with in the Book of Job.
Yes, God did declare Job as righteous but that was in relation to his outward works alone. His behavior was impeccable but his heart was sinful just like all humans. God was dealing with Job’s inherent sinfulness; his pride and his sin nature.
In the main part of the book, you see Job’s friends insisting that there must have been some kind of sin in his life because God does not punish an innocent person. Job then repeatedly defends himself, justifying his behavior. The only issue is that his behavior was not at issue with God. Job’s friends and Job all must have attended the same church (LOL) for all had the same theology. That theology was that you reap what you sow; if you have something evil happen to you, then you must have acted in some way to deserve the punishment. All three had this world view; only Job’s friends insisted Job sinned and Job insisted that he didn’t.
Chapter 32, verse one is an important verse. When Job’s three friends tire of trying to convince Job of his sin, the bible says:
Job 32:1 (KJV):
So these three men ceased to answer Job, because he was righteous in his own eyes.
Job was so self righteous, that it appears that he has a God complex. Just read the account in chapter 29. When Job is now tired of ranting toward God, he then starts to reflect on the good old days when he was a respected person in the community. To Job, his position in the community was the most important thing that Job lost!!!! This chapter is extremely telling. Job’s pride is enormous.
Job 29 (KJV):
2 Oh that I were as in months past, as in the days when God preserved me; 3 When his candle shined upon my head, and when by his light I walked through darkness; 4 As I was in the days of my youth, when the secret of God was upon my tabernacle; 5 When the Almighty was yet with me, when my children were about me; 6 When I washed my steps with butter, and the rock poured me out rivers of oil; 7 When I went out to the gate through the city, when I prepared my seat in the street! 8 The young men saw me, and hid themselves: and the aged arose, and stood up. 9 The princes refrained talking, and laid their hand on their mouth. 10 The nobles held their peace, and their tongue cleaved to the roof of their mouth. 11 When the ear heard me, then it blessed me; and when the eye saw me, it gave witness to me: 12 Because I delivered the poor that cried, and the fatherless, and him that had none to help him. 13 The blessing of him that was ready to perish came upon me: and I caused the widow's heart to sing for joy. 14 I put on righteousness, and it clothed me: my judgment was as a robe and a diadem. 15 I was eyes to the blind, and feet was I to the lame. 16 I was a father to the poor: and the cause which I knew not I searched out. 17 And I brake the jaws of the wicked, and plucked the spoil out of his teeth. 18 Then I said, I shall die in my nest, and I shall multiply my days as the sand. 19 My root was spread out by the waters, and the dew lay all night upon my branch. 20 My glory was fresh in me, and my bow was renewed in my hand. 21 Unto me men gave ear, and waited, and kept silence at my counsel. 22 After my words they spake not again; and my speech dropped upon them. 23 And they waited for me as for the rain; and they opened their mouth wide as for the latter rain. 24 If I laughed on them, they believed it not; and the light of my countenance they cast not down. 25 I chose out their way, and sat chief, and dwelt as a king in the army, as one that comforteth the mourners.
Job's heart is then revealed in Chapter 30. After the praise of himself has ended, he remembers that there are these young men that have nothing but distain for Job's present situation. Job then shows the true nature of his heart and the fact that he hates his neighbor (therefore cannot possibly love God) and in his pride, says that he would have treated these men's fathers worse than animals.
Job 30:1 (KJV)
But now they that are younger than I have me in derision, whose fathers I would have disdained to have set with the dogs of my flock.
At the end of the Book, Elihu the prophet comes in a reams out Job for justifying himself instead of justifying God. God them comes behind Elihu and does essentially the same thing.
Job then finally realizes his problem as pride and self righteousness, covers his mouth and says that he is a vile man. God, seeing Job realize and understand his inherent sin, releases Job from his plight and the mercy of God restores Job to greater than when he was self righteous. This is a great metaphor about man’s righteousness verses God’s righteousness.
I'll take the questions one at a time starting with the Title.
Who was the original audience for the story of Job?
It seems clear that it was written as a story about a non-Hebrew for a Hebrew audience.
Was the story Hebrew in origin?
It's impossible to know if the author was influenced by the similar stories about suffering that were probably well known in ancient near eastern literature. Given the author's literary ability it would seem he was widely read so my guess is yes, he was aware of them. This was a time of oral story tellers, and these stories traveled over great distances and were passed down for generations.
Would it have been intended as a metaphor for the people undergoing a period of suffering...?
It's not a metaphor.
I'll sum up, and hopefully answer the remaining questions.
Although the challenge to concept of retribution (punishment for sin and reward for goodness) is clearly in view throughout the narrative, I believe the over-arching message to be that we as men do not know God's ultimate purposes, and therefore should be humble in our approach to God and our brother in his suffering.
The main support for this is that neither Job nor his friends are never given the actual reason for his suffering. They simply accept that God is sovereign and they are not... and Job gets his stuff back.
One final thought, I strongly disagree with the conclusions of the other answer criticizing Job for self-righteousness. This is reading Job's seemingly "boastful" statements through our cultural eyes, and is completely contradicted by the council scene and God's discussion with the adversary.
For further study see: John Walton videos on youtube and Robert Alter's intro to his translation of Job in "The Wisdom Books: Job, Proverbs, and Ecclesiastes: A Translation with Commentary ".