Mutate() function works for one set of input files. but throws error when the input file is changed.

First, here is a guide you can read about how to provide a minimal reproducible example.

Your error seems to relate to what would appear to be a custom function. (i.e., we can't know what it is, or how it works if you don't provide us that information...) Its returning a result with dimensions that don't fit the data.frame structure expectations. One way to proceed might be to naively capture its results into a list, though this can make for difficult programming. Another way would be to understand the function and to use it (or decide not to use it, but to use something else ) based on its appropriateness for the task.