I'd say this account was written, at least in part, to explain why bad things happen to good people. Although God allowed the bad to happen, and accepted responsibility for it, the disasters were actually the work of Satan.
I see that after the initial losses, Job still praised the name of YHWH, and after being afflicted with sores, Job said, "Shall we accept good from God, and not trouble?" Now that's one tough guy.
For the sake of argument, I'm going to take the position that this was a real, historical series of events. About the sons and daughters being killed, we aren't told much about them or the relationships between them and Job. We know the kids liked to party, and Job took it upon himself to sacrifice on their behalf. Were these wild, ungodly parties? Job certainly felt the need to sacrifice on their behalf. How much did Job really know about what went on with them? How close were the relationships with his kids? Did the kids disregard God? Why didn't they make their own burnt offerings (at least, there's no mention they did)? As for the other losses, we don't know anything about the other people or what kind of operation Job ran. Maybe, with all his personal righteousness, Job didn't manage things well for God. My point is that there is a lot we don't know in this story. While the person who wrote this down (possibly from oral tradition) didn't think the behind-the-scenes details were important for the ones who would hear or read it, those details might give our skeptical minds something to ponder about God's rationale.
Interesting that Satan didn't eliminate the wife ("I can use her").
The fact is that bad things do happen to good people. Sometimes we understand why, many times we don't. But you know, we don't have all the facts--past, present, future. If we consider things from God's perspective, at least sometimes, maybe there isn't a question of why, but rather, why not.
Also, we often know when bad things happen to good people, but we seldom are aware of when bad things DON'T happen to good people. Some people just seem to have been in the wrong place at the wrong time, but who can say how many times we missed being in the wrong place, such as when a slight delay in leaving prevents our car from being at a place where it would have collided with another. Our focus is on what went wrong rather than on what didn't go wrong.
I think Job's appreciation and care of what he had after his life was restored was much greater than before the losses. Too bad Job isn't around to give us his perspective. But then, there may be a few "Jobs" in our world today to ask for theirs.