Robert,
I would take a different approach. HoldForm is difficult to control and it can have strange side effects. I would use notebook programming to grab the input cell and manipulate it. I think it will be more reliable:
First, define a function that will take an input string and parse it, and save the file using the filename. For example, "p1 = Plot[Cos[x], {x, 0, 6}]" gets saved by making a jpg from p1 and calling the file "Plot[Cos[x], {x, 0, 6}].jpg"
saveFile[x_] :=
Module[{lst}, lst = StringSplit[x, "="];
Export[lst[[2]] <> ".jpg", ToExpression[lst[[1]]], "jpg"]]
Next, make a function to grab the previous input line and send it to saveFile[]: (Note that most of the code below is so that the result is inserted after the existing cell. It makes for a cleaner notebook. If you do not care, many of the lines in this function go away and the save is inserted before the plot)
saveIt2[] :=
Module[{nb = InputNotebook[], currentCell},
SelectionMove[nb, Previous, CellContents, 3]; (* go back to the previous input cell *);
currentCell = NotebookRead[nb]; (* save the cell *);
SelectionMove[nb, Next, Cell, 2]; (* move back down selecting my cell *);
SelectionMove[nb, After, Cell]; (* move after my cell *);
NotebookWrite[nb, currentCell]; (* insert the contents of the saved cell *);
SelectionMove[nb, All, Cell]; (* select the inserted the cell *);
NotebookApply[nb,
"saveFile[ToString[\"\[SelectionPlaceholder]\"]]"]; (* insert the save function *);
SelectionEvaluateCreateCell[nb] (* evaluate the new cell and save the file *) ]
To use the code:
p1 = Plot[Cos[x], {x, 0, 6}]
saveIt2[]
This will go and create a new cell with the save function and export the plot. I suppose an upgrade would be to create a function or button that deletes all the saveFile cells when complete so you can reevaluate the notebook without side effects.
I hope this helps.
Regards,
Neil