Are you sure this function is casing the problem? Does the problem go away if you comment out the add_action line?
If this function is causing the problem the only thing I can think of by looking at this function is that in may have to do with the ‘post_name’ value. Try commenting out those lines and see what happens.