Akshay
In the Details of the Python Code object make sure that the 'Target Callback' is set to 'After Post'. I tested your above code on a simple model and it worked though I did change what was written to the file from result data to just the DP number. Since I only wanted to verify that something was written at each DP.
Mike