My code is working fine where I am writing everything into the file including exit. Then why so its failing?