Could it be a case sensitivity issue?
You have this line:
return sourceFileName.Replace("PARTS", "STEP").Replace("SLDPRT", "STEP");
What if the sourceFileName is Part1.sldprt for example?
Thanks for pointing this out. It was exactly the reason why this happened.
Since I was coding for the first time on Windows, I had just assumed that its case insensitive. It works fine now.