What is possibly happening is that something (probably the API you are using) has a lock on the file, preventing the delete.
When you do this in debug and step through, because you're stepping through it at a "slow" pace, the lock has been released, and the file is successfully deleted.
You should put the deletion code in a retry loop with an exception handler, which sleeps for a second or so and then tries again, giving OS a chance to relinquish the lock.
Another thing to consider is that, assuming you are running this as a service when in production, the service is running under a different user-account than when you debug it through visual studio (assuming you are not attaching to the service - it's hard to tell here). Check that the account the service is running under has permissions to delete the file in the first place.