in reply to
When you write
...fails only when the script is run in background
I wonder if you mean "when run from cron." If so, you should be aware that most cron implementations start processes in a limited environment. My first guess would be that kerberos is missing information that it normally fetches from an environment variable and this is causing it to fail. Perhaps the cache is in a non-standard location? In any event, as previous poster suggested, the output of the error method would be useful in determining the cause of your failure.