How does Temporal know exactly which line of code the server executed before crashing?

Does temporal-server keep track of every line being executed ? Where the info will be stored in the history?

No, your workers execute your workflow code. Temporal uses event sourcing and records all external api calls for an execution (such as client request to create workflow execution, commands sent to it from your workers, signals, etc) in the execution event history.
When an execution needs to be recovered to the latest state, your workers use the so far recorded history to put its in the same state as it was before.
Watch this video that has a great demo on this topic.

Does temporal caches result of the workflow ?

Result of execution is recorded in the executions event history (and persisted). It’s available after workflow completes up to the retention period configured for the namespace it ran on. After this retention is reached workflow history (and mutable state as well as visibility data) are removed for this execution.

The result will be dependant on the parameter ?

If I understand your question correctly yes workflow execution can produce different result for different input parameter values. The workflow code itself has to be deterministic, meaning for the same set of inputs (values) it should perform same actions (orchestration logic).

Does Temporal have heart beat mechanism?

Yes activities can have heartbeat timeout and can heartbeat, see this video for more info.