When I remove the free(), the program runs perfectly even though I'm entering more than the allocated size.
Entering more than allocated size is called undefined behavior. This is an error, despite the fact that your program may appear to be "running fine".
The main problem with undefined behavior is that your program does not fail fast. Essentially, the penalty for having undefined behavior is delayed until some future time - for example, when you allocate again, or when you free.
malloc
stores some special information in the allocated block that lets free
run. The "nvalid next size" error usually means that your code has written over some of that hidden block of data.
To fix this problem you need to change your code so that it never writes past the allocated length. If you are having trouble detecting precisely the spots that need to change, consider using valgrind or another memory profiler.
To prevent scanf
from writing over your allocated size use the size in the format string:
scanf("%49s",usr_input); // Pass 49 for the length, because you have 50 bytes, and you need 1 byte for '\0'