You have to quote the expression in single quotes in the style of an SQL query because that is what it is.
arcpy.CalculateField_management(Input, "Filename","'"+ expression+"'", "PYTHON")To debug the expressions run the tool interactively, then grab a Python snippet from the results panel and paste it into your script.This will show you some working code that you can then edit to replace parts with a variable.In a script it is actually easier to use a cursor than the CalculateField which is really only designed for Modelbuilder.A cursor is just as fast, can be much easier to write and debug and can handle errors such as null values with an if statement.(Untested pseudocode)
with arcpy.da.UpdateCursor(Input,['filename']) as cur:
for row in cur:
row = expression
No gymnastics needed to quote strings. The with closes the cursor.